<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class activity  extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
                public $URL;
                public function __construct() {
                    parent::__construct();
                    $this->URL = $this->uri->uri_to_assoc();
                    $this->authen_model->CheckPermission();
                    $this->load->model("collegian_model");
                    $this->load->model("activity_model");
                    $this->load->model("major_model");
                }
                
                public function export_report_print_code(){
                    if(trim($this->URL["ID"]) != ""){
                           $this->load->model("collegian_activity_model");
                           $data["report_code"] = $this->collegian_activity_model->get_collegian_in_activity( trim($this->URL["ID"]) );
                           $this->load->view("collegian/export_report_print_code_page",$data);
                    }
                }
                /* หน้าแสดงรายงาน */
                public function printcode(){
                    $CI =& get_instance();
                    $data["CI"] = $CI;
                    if(trim($this->URL["ID"]) != ""){
                           $this->load->model("collegian_activity_model");
                           $data["act_id"] = trim($this->URL["ID"]);
                           //$data["report_code"] = $this->collegian_activity_model->get_collegian_in_activity( trim($this->URL["ID"]) );
                            $data["majors"] = $this->collegian_model->get_majors();
                                $this->templates
                                        ->appendJs("admin.js")
                                        ->appendJs("activity.js")
                                        ->setContent($this->load->view("collegian/report_print_code_page",$data,true))
                                        ->setTitle("ข้อมูลกิจกรรม")
                                        ->rander();
                    }
                }
                
                public function printhtml(){
                    $CI =& get_instance();
                    $data["CI"] = $CI;
                    if(trim($this->URL["ID"]) != ""){
                           $this->load->model("collegian_activity_model");
                           $data["act_id"] = trim($this->URL["ID"]);
                            $data["majors"] = $this->collegian_model->get_majors();
                            $this->load->view("collegian/export_html/report_print_with_register",$data);
                    }
                }
                
	public function index()
	{
                      $this->add_collegian_form();
	}
        
                public function view_activitys(){
                    $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->appendJs("activity.js")
                                ->appendJs("upload.js")
                                ->setContent($this->load->view("activity/view_activitys",$data,true))
                                ->setTitle("ข้อมูลกิจกรรม")
                                ->rander();
                }
                
                /* ค้นหาข้อมูลกิจกรรมในหน้ารายงาน ::รายงานการลงทะเบียนเข้าร่วมกิจกรรมของนักศึกษา */
                public function search_activity_report(){
                    
                    $data["activitys_datay"] = $this->activity_model->search_activity_event_with_sum(
                            $_POST
                    ); 

                    $count = $this->db_model->getCount();
                    $data["count"] = $count;
                    $this->load->view("activity/view_activity_table_report",$data);
                }
                
                public function report(){
                    $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->appendJs("activity.js")
                                ->setContent($this->load->view("activity/report_activitys",$data,true))
                                ->setTitle("ข้อมูลกิจกรรม")
                                ->rander();
                }
                
                /* รายงานการลงทะเบียนเข้าร่วมกิจกรรมของนักศึกษา  */
                public function activity_report_01(){
                    $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->appendJs("activity.js")
                                ->setContent($this->load->view("activity/reports/report_activitys_form_01",$data,true))
                                ->setTitle("ข้อมูลกิจกรรม")
                                ->rander();
                }
                
                /* รายงานการเข้าร่วมกิจกรรม-ขาดกิจกรรม นักศึกษารายคน  */
                public function activity_report_02(){
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->setContent($this->load->view("activity/reports/report_activitys_form_02",$data,true))
                                ->setTitle("แสดงข้อมูลนักศึกษา")
                                ->rander();
                }
                
                /* รายงานการเข้าร่วมกิจกรรม-ขาดกิจกรรม นักศึกษารายคน  */
                public function activity_report_03(){
                        $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->setContent($this->load->view("activity/reports/report_activitys_form_03",$data,true))
                                ->setTitle("แสดงข้อมูลนักศึกษา")
                                ->rander();
                }
                
                public function search_collegian_report_admin_02(){
                    
                    $data["collegian_datay"] = $this->collegian_model->search_collegian(
                            mysql_escape_string($_POST["txt_search"]) ,
                            mysql_escape_string($_POST["group_type"])
                    );
                    $data["count"] = $this->db_model->getCount();
                    $this->load->view("activity/reports/report_activitys_form_02_table",$data);
                }
                
                public function search_teacher_report_admin_03(){
                    $this->load->model("teacher_model");
                    $data["teacher_datay"] = $this->teacher_model->getTeacher(
                    );
                    $data["count"] = $this->db_model->getCount();
                    $this->load->view("activity/reports/report_activitys_form_03_table",$data);
                }
                
                /*  แสดงการเข้าร่วมกิจกรรมของนักศึกษาตามรหัสนักศึกษาที่ระบุ */
                public function display_collegian_activity(){
                    if($this->URL["ID"] != ""){
                            $this->load->model("collegian_activity_model");
                            $collegian_datay = $this->collegian_model->get_collegian_by_id(mysql_escape_string($this->URL["ID"]));
                            if( $collegian_datay->collegian_id != ""){
                                        $data["activity_y"] = $this->collegian_activity_model->get_report_activity_y(trim($this->URL["ID"]));
                                        $data["activity_n"] = $this->collegian_activity_model->get_report_activity_n(trim($this->URL["ID"]));
                                        $data["collegian_datay"] = $collegian_datay;
                                        $data["ID"] = $this->URL["ID"];
                                        $this->templates
                                                ->setContent($this->load->view("activity/reports/display_activity_by_collegians",$data,true))
                                                ->setTitle("ระบบออกรายงานการเข้าร่วมกิจกรรมนักศึกษา")
                                                ->rander();
                            }
                    }
                }
                
                /*  แสดงการเข้าร่วมกิจกรรมของนักศึกษาตามรหัสนักศึกษาที่ระบุ */
                public function print_display_collegian_activity(){
                    if($this->URL["ID"] != ""){
                            $this->load->model("collegian_activity_model");
                            $collegian_datay = $this->collegian_model->get_collegian_by_id(mysql_escape_string($this->URL["ID"]));
                            if( $collegian_datay->collegian_id != ""){
                                        $data["activity_y"] = $this->collegian_activity_model->get_report_activity_y(trim($this->URL["ID"]));
                                        $data["activity_n"] = $this->collegian_activity_model->get_report_activity_n(trim($this->URL["ID"]));
                                        $data["collegian_datay"] = $collegian_datay;
                                       $this->load->view("activity/reports/print_display_activity_by_collegians",$data);
                                           
                            }
                    }
                }
                
                
                public function search_activity(){
                    $data["activitys_datay"] = $this->activity_model->search_activity_event(
                            $_POST
                    );
                    $data["count"] = $this->db_model->getCount();
                    $this->load->view("activity/view_activity_table",$data);
                }
        
                public function add_activity_form(){
                    $data["majors"] = $this->collegian_model->get_majors();
                        $this->templates
                                ->appendJs("admin.js")
                                ->appendJs("activity.js")
                                ->setContent($this->load->view("activity/frm_create_activity",$data,true))
                                ->setTitle("สร้างข้อมูลกิจกรรม")
                                ->rander();
                }
                
                public function create_activity_event(){
                    $this->activity_model->add_activity($_POST);
                    print('<script> top.callback_add_activity()  </script>');
                }
                
                public function get_dialog_edit_activity(){
                    if(isset($_POST["activity_id"])){
                        $data["activity_datay"] = $this->activity_model->get_activity( $_POST["activity_id"] );
                        $data["majors"] = $this->major_model->get_group_major_relation( $_POST["activity_id"]  );
                        $data["teacher"] = $this->major_model->get_group_teacher_relation( $_POST["activity_id"]  );
                        $data["photos"] = $this->activity_model->get_photos($_POST["activity_id"]);
                        $this->load->view("activity/dialog_edit_activity",$data);
                    }
                }
                
                public function set_update_activity(){
                    $this->activity_model->update_activity($_POST);
                }
                /* ลบรายข้อมูลสาขาที่เข้าร่วมกิจกรรม */
                public function unset_major_of_activity(){
                    if(isset($_POST["major_relation_id"])){
                        $major_relation_id = mysql_escape_string( $_POST["major_relation_id"] );
                        $this->activity_model->delete_major_of_activity( $major_relation_id );
                    }
                }
        
               
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */